package edu.dayu.controller;


import com.github.pagehelper.PageInfo;
import edu.dayu.pojo.Paging;
import edu.dayu.pojo.Type;
import edu.dayu.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;


@Controller
public class TypeController {
    @Autowired
    private TypeService typeService;


    @GetMapping("/blogstype")
    public String toBlogType(Paging paging, Model model){
        PageInfo<Type> typePageInfo = typeService.listType(paging);
        model.addAttribute("types",typePageInfo);
        return "admin/blogs-types";
    }

    @PostMapping("getType")
    public String  getType(int id,Model model) {
        Type type = typeService.getType(id);
        model.addAttribute("singletype",type);
//        PageInfo<Type> typePageInfo = typeService.listType(new Paging());
//        model.addAttribute("types",typePageInfo);
        return "admin/blogs-types::updateload";
    }


    @PostMapping("saveType")
    @ResponseBody
    public Boolean saveType(Type type) {
        Boolean saveType = typeService.saveType(type);
        return saveType;
    }

    @PostMapping("updateType")
    @ResponseBody
    public Boolean updateType(Type type) {
        return typeService.updateType(type);
    }

    @PostMapping("deleteType")
    @ResponseBody
    public void deleteType(int id) {
        typeService.deleteType(id);
    }
}
